shader DWParquetTile (

        float DiffuseAmt = 0.75 ,
        float SpecularAmt = 0.15,
        float Roughness = 0.025,
        color SpecularColor = color(1.0),
        float RingScale = 25.0,
        float GrainScale = 55.0,
        float Grainy = 1.0,
        float Wavy = 0.08,
        float TextureScale = 5.0,
        color LightWood = color (0.57, 0.292, 0.125),
        color DarkWood  = color (0.275, 0.15, 0.06),
        color GrooveColor  = color (0.05, 0.04, 0.015),
        int PlanksPerTile = 1,
        float PlankWidth = 0.2,
        float PlankVary = 0.6,
        float GrooveWidth = 0.1,
        output color BSDF = .5 )
{
#define snoise(x) (2 * noise((x)) - 1)
#define boxstep(a,b,x) (clamp(((x)-(a))/((b)-(a)),0,1))
#define MINFILTERWIDTH 1.0e-7

        vector Vector = P;
    float su = Vector[0];
    float tv = Vector[1];
    float r, r2;
    point Nf;
    float whichrow, whichplank;
    float swidth, twidth, fwidth, ss, tt, w, h, fade, ttt;
    color Ct, woodcolor;
    float groovy;
    float PGWIDTH, PGHEIGHT, GWF, GHF;
    float tilewidth, whichtile, tmp, planklength;

    PGWIDTH = PlankWidth+GrooveWidth;
    planklength = PGWIDTH * PlanksPerTile - GrooveWidth;
    PGHEIGHT = planklength+GrooveWidth;
    GWF = GrooveWidth*0.05/PGWIDTH;
    GHF = GrooveWidth*0.05/PGHEIGHT;

    /* Determine how wide in s-t space one pixel projects to */
    swidth = (max (abs(Dx(su)*su) + abs(Dy(su)*tv), MINFILTERWIDTH) / PGWIDTH) * TextureScale;
    twidth = (max (abs(Dx(tv)*su) + abs(Dy(tv)*tv), MINFILTERWIDTH) / PGHEIGHT) * TextureScale;
    fwidth = max(swidth,twidth);

    ss = (TextureScale * su) / PGWIDTH;
    whichrow = floor (ss);
    tt = (TextureScale * tv) / PGHEIGHT;
    whichplank = floor(tt);
    if (mod (whichrow/PlanksPerTile + whichplank, 2) >= 1) {
        ss = TextureScale * tv / PGWIDTH;
        whichrow = floor (ss);
        tt = TextureScale * su / PGHEIGHT;
        whichplank = floor(tt);
        tmp = swidth;  swidth = twidth;  twidth = tmp;
    } 
    ss -= whichrow;
    tt -= whichplank;
    whichplank += 20*(whichrow+10);

    /*
     * Figure out where the grooves are.  The value groovy is 0 where there
     * are grooves, 1 where the wood grain is visible.  Do some simple
     * antialiasing.
     */
    if (swidth >= 1)
        w = 1 - 2*GWF;
    else {
        w = clamp (boxstep(GWF-swidth,GWF,ss), max(1-GWF/swidth,0), 1)
        - clamp (boxstep(1-GWF-swidth,1-GWF,ss), 0, 2*GWF/swidth);
    }
    if (twidth >= 1)
        h = 1 - 2*GHF;
    else {
        h = clamp (boxstep(GHF-twidth,GHF,tt), max(1-GHF/twidth,0),1)
        - clamp (boxstep(1-GHF-twidth,1-GHF,tt), 0, 2*GHF/twidth);
    }
    /* This would be the non-antialiased version:
     * w = step (GWF,ss) - step(1-GWF,ss);
     * h = step (GHF,tt) - step(1-GHF,tt);
     */
    groovy = w*h;


    /*
     * Add the ring patterns
     */
    fade = smoothstep (1/RingScale, 8/RingScale, fwidth);
    if (fade < 0.999) {
        ttt = tt/4+whichplank/28.38 + Wavy * noise (8*ss, tt/4);
        r = RingScale * noise (ss-whichplank, ttt);
        r -= floor (r);
        r = 0.3 + 0.7 * smoothstep(0.2, 0.55, r) * (1 - smoothstep(0.75, 0.8, r));
        r = (1-fade)*r + 0.65*fade;

        /*
         * Multiply the ring pattern by the fine grain
         */
        fade = smoothstep (2/GrainScale, 8/GrainScale, fwidth);
        if (fade < 0.999) {
            r2 = 1.3 - noise (ss*GrainScale, (tt*GrainScale/4));
            r2 = Grainy * r2*r2 + (1-Grainy);
            r *= (1-fade)*r2 + (0.75*fade);
        }
        else
            r *= 0.75;
    }
    else
        r = 0.4875;
  

    /* Mix the light and dark wood according to the grain pattern */
    woodcolor = mix (LightWood, DarkWood, r);

    /* Add plank-to-plank variation in overall color */
    woodcolor *= (1-PlankVary/2 + PlankVary * noise (whichplank+0.5));

    Ct = mix (GrooveColor, woodcolor, groovy);
    Nf = normalize(N);
BSDF =  Ct * DiffuseAmt;

   // BSDF = Ct * DiffuseAmt * diffuse(Nf);
  //  BSDF += SpecularColor * SpecularAmt;
}